package com.sec.android.app.myfiles.module.local.file;

import android.content.Context;
import android.database.Cursor;
import android.provider.MediaStore.Files.FileColumns;

import com.sec.android.app.myfiles.info.AppConstants;
import com.sec.android.app.myfiles.module.abstraction.FileRecord;
import com.sec.android.app.myfiles.navigation.NavigationInfo;
import com.sec.android.app.myfiles.provider.DbTableInfo;

public class LocalHoverFileListAdapterImp extends LocalFileListAdapterImp {

    public LocalHoverFileListAdapterImp(Context context, NavigationInfo navigationInfo, int layout, Cursor c, int flags) {
        super(context, navigationInfo, layout, c, flags);
    }

    @Override
    protected FileRecord _getFileRecord(Cursor cursor) {
        FileRecord ret = null;

        if (cursor != null) {
            final int pathIndex = cursor.getColumnIndex(FileColumns.DATA);
            String full_path = cursor.getString(pathIndex);
            ret = new LocalFileRecord(full_path, mContext);
            ret.setGear360Contents(isGear360Contents(cursor));
        }
        return ret;
    }

    private boolean isGear360Contents(Cursor cursor) {
        boolean isGear360Contents = false;
        final int sefFileTypeIndex = cursor.getColumnIndex(DbTableInfo.COLUMN_NAME_SEF_FILE_TYPE);
        final int isGear360VideoIndex = cursor.getColumnIndex(DbTableInfo.COLUMN_NAME_GEAR360_VIDEO);
        if (sefFileTypeIndex != -1) {
            isGear360Contents |= (cursor.getInt(sefFileTypeIndex) == AppConstants.SEF_FILE_TYPE_GEAR_360_IMAGE);
        }
        if (!isGear360Contents && isGear360VideoIndex != -1) {
            isGear360Contents |= (cursor.getInt(isGear360VideoIndex) == 1);
        }
        return isGear360Contents;
    }
}
